package br.com.rapidrest.util;

import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class MessagesBundle {

	private static final long serialVersionUID = 6959023277444042865L;

	private ResourceBundle resourceBundle;

	public MessagesBundle(ResourceBundle resourceBundle) {
		super();
		this.resourceBundle = resourceBundle;
	};

	public String get(String key) {
		String value = null;

		try {
			value = resourceBundle.getString(key);
		} catch (MissingResourceException e) {
			value = key;
		}

		return value;
	}

	public String format(String key, Object... arguments) {
		String value = MessageFormat.format(get(key), arguments);
		return value;
	}

	public String get(String key, List<Object> arguments) {
		return format(key, arguments.toArray());
	}

	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}

	public Locale getLocale() {
		return resourceBundle.getLocale();
	}

}
